package com.powerwyx.shortlink.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powerwyx.shortlink.admin.common.convention.result.Result;
import com.powerwyx.shortlink.admin.common.convention.result.Results;
import com.powerwyx.shortlink.admin.remote.ShortLinkActualRemoteService;
import com.powerwyx.shortlink.admin.remote.dto.ShortLinkBatchCreateDTO;
import com.powerwyx.shortlink.admin.remote.dto.ShortLinkCreateDTO;
import com.powerwyx.shortlink.admin.remote.dto.ShortLinkPageDTO;
import com.powerwyx.shortlink.admin.remote.dto.ShortLinkUpdateDTO;
import com.powerwyx.shortlink.admin.remote.vo.ShortLinkBatchCreateVO;
import com.powerwyx.shortlink.admin.remote.vo.ShortLinkCreateVO;
import com.powerwyx.shortlink.admin.remote.vo.ShortLinkPageVO;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 王艺锡
 * @version 1.0
 */
@Slf4j
@RestController
public class ShortLinkController {
    @Autowired
    private ShortLinkActualRemoteService shortLinkActualRemoteService;

    /**
     * 创建短链接
     * @param shortLinkCreateDTO
     * @return
     */
    @PostMapping("/api/shortlink/admin/v1/create")
    public Result<ShortLinkCreateVO> createShortLink(@RequestBody ShortLinkCreateDTO shortLinkCreateDTO) {
        return shortLinkActualRemoteService.createShortLink(shortLinkCreateDTO);
    }


    /**
     * 批量创建短链接
     */
    @PostMapping("/api/short-link/admin/v1/create/batch")
    public void batchCreateShortLink(@RequestBody ShortLinkBatchCreateDTO requestParam, HttpServletResponse response) {
        Result<ShortLinkBatchCreateVO> shortLinkBatchCreateVOResult = shortLinkActualRemoteService.batchCreateShortLink(requestParam);
    }


    /**
     * 根据分组进行分页查询短链接
     *
     * @param shortLinkPageDTO
     * @return
     */
    @GetMapping("/api/shortlink/admin/v1/page")
    public Result<Page<ShortLinkPageVO>> shortLinkPage(ShortLinkPageDTO shortLinkPageDTO) {
        return shortLinkActualRemoteService.shortLinkPage(
                shortLinkPageDTO.getGid(),
                shortLinkPageDTO.getOrderTag(),
                shortLinkPageDTO.getCurrent(),
                shortLinkPageDTO.getSize()
        );
    }


    /**
     * 修改短链接信息
     *
     * @param shortLinkUpdateDTO
     * @return
     */
    @PostMapping("/api/shortlink/admin/v1/update")
    public Result<Void> updateShortLink(@RequestBody ShortLinkUpdateDTO shortLinkUpdateDTO) {
        shortLinkActualRemoteService.updateShortLink(shortLinkUpdateDTO);
        return Results.success();
    }




}
